<?php
namespace App\Api\Service;

use App\Api\Repositories\OptionRepositories;
use App\Api\Repositories\Article\ArticleRepositories;

class DataService{
    protected $repositories;

    public function __construct(){
        $this->OptionRepositories = new OptionRepositories();
        $this->ArticleRepositories = new ArticleRepositories();
    }

    /**
     * 获取指定或全部类型的选项值
     *
     * @param string $type 选项值
     * @return void
     */
    public function get_options($type){
        if($type == 'all'){
            return $this->OptionRepositories->get_all_data();
        }else{
            return $this->OptionRepositories->get_data($type);
        }
    }

    /**
     * 获取指定文章信息
     *
     * @param int $id 文章id
     * @return void
     */
    public function get_article($id){
        $data = $this->ArticleRepositories->get_data($id);
        return ['title'=> $data->title, 'content'=> $data->content];
    }
}